<template>
  <ContentWrap :styleParams="{height: 'calc(100vh - 150px)', padding: '20px'}">
    <HeaderTitle title="人口密度判定条件" content="设置响应等级判定时，人口密度的计算规则"/>
    <el-form ref="ruleForm" v-loading="formLoading" :model="regionForm" :rules="formRules" label-width="120px">
      <el-row>
        <el-col>
          <p class="content">1) 震級M&lt; <el-form-item label-width="0px" prop="field1" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field1" controls-position="right"
                style="width: 150px;" />
              </el-form-item>，统计震中
              <el-form-item label-width="0px" prop="field2" style="display: inline-block;">
                <el-input-number :precision="1" v-model="regionForm.field2" controls-position="right"
                  style="width: 150px;" />
              </el-form-item>公里范围内人口密度。
          </p>
          <p class="content">2)
            <el-form-item label-width="0px" prop="field3" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field3" controls-position="right"
                style="width: 150px;" />
            </el-form-item>≤震级M&lt; <el-form-item label-width="0px" prop="field4" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field4" controls-position="right"
                style="width: 150px;" />
              </el-form-item>，统计震中
              <el-form-item label-width="0px" prop="field5" style="display: inline-block;">
                <el-input-number :precision="1" v-model="regionForm.field5" controls-position="right"
                  style="width: 150px;" />
              </el-form-item>公里范围内人口密度
          </p>
          <p class="content">3)
            <el-form-item label-width="0px" prop="field6" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field6" controls-position="right"
                style="width: 150px;" />
            </el-form-item>≤震级M&lt; <el-form-item label-width="0px" prop="field7" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field7" controls-position="right"
                style="width: 150px;" />
              </el-form-item>，统计震中
              <el-form-item label-width="0px" prop="field8" style="display: inline-block;">
                <el-input-number :precision="1" v-model="regionForm.field8" controls-position="right"
                  style="width: 150px;" />
              </el-form-item>公里范围内人口密度
          </p>
          <p class="content">4) 震級M≥
            <el-form-item label-width="0px" prop="field9" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field9" controls-position="right"
                style="width: 150px;" />
            </el-form-item>，统计震中
            <el-form-item label-width="0px" prop="field10" style="display: inline-block;">
              <el-input-number :precision="1" v-model="regionForm.field10" controls-position="right"
                style="width: 150px;" />
            </el-form-item>公里范围内人口密度。
          </p>
        </el-col>
        <el-col style="text-align: center;">
          <el-button type="primary" @click="submit">保存</el-button>
        </el-col>
      </el-row>
    </el-form>
  </ContentWrap>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue'
import * as RegionApi from '@/api/responseLevel/Region'
defineOptions({ name: 'Region' })
const message = useMessage() // 消息弹窗

const formLoading = ref(true) // 列表的加载中
const regionForm = ref({
  field1: 5.2,
  field2: 10,
  field3: 5,
  field4: 6,
  field5: 20,
  field6: 6,
  field7: 7,
  field8: 50,
  field9: 7,
  field10: 100
})
const formRules = reactive({
  field1: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field2: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field3: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field4: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field5: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field6: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field7: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field8: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field9: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
  field10: [{ required: true, message: '数值不能为空', trigger: 'blur' }],
})
/** 查询列表 */
const getList = async () => {
  formLoading.value = true
  try {
    regionForm.value = await RegionApi.getRegion()
  } finally {
    formLoading.value = false
  }
}
/** 提交按钮 */
const ruleForm = ref() // 表单 Ref
const submit = async () => {
  // 校验表单
  if (!ruleForm) return
  const valid = await ruleForm.value.validate()
  if (!valid) return
  // 提交请求
  formLoading.value = true
  // 提交请求
  try {
    RegionApi.updateRegion(regionForm.value).then((res) => {
      message.success('保存成功！')
      getList()
    })
  } finally {
    formLoading.value = false
  }
};
/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
